package com.shengsiyuan.netty.sixthexample.server;

import com.shengsiyuan.netty.sixthexample.proto.MyDataInfo;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

public class TestServerHandler extends SimpleChannelInboundHandler<MyDataInfo.Message> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, MyDataInfo.Message msg) throws Exception {
        MyDataInfo.Message.DataType dataType = msg.getType();
        if (dataType == MyDataInfo.Message.DataType.PERSON){
            MyDataInfo.Person person = msg.getPerson();
            System.out.println(person.getName());
            System.out.println(person.getAddress());
            System.out.println(person.getAge());
        }else if (dataType == MyDataInfo.Message.DataType.TEACHER){
            MyDataInfo.Teacher teacher = msg.getTeacher();
            System.out.println(teacher.getName());
            System.out.println(teacher.getAddress());
            System.out.println(teacher.getAge());
        }else {
            MyDataInfo.Student student = msg.getStudent();
            System.out.println(student.getName());
            System.out.println(student.getAddress());
            System.out.println(student.getAge());
        }

    }


}
